package com.pxxy.mapper;

import com.pxxy.entity.Course;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

public interface CourseMapper {

    @Insert({"insert into t_course(id,course_name,minutes,description) " +
            "values(null,#{courseName},#{minutes} ,#{description} )"})
    @Options(useGeneratedKeys = true,keyColumn = "id", keyProperty = "id")
    int save(Course course);

    @Delete("delete from t_course where id = #{value}")
    int delete(Serializable id);

    @Update("update t_course c set c.course_name=#{courseName} ," +
            "c.minutes=#{minutes} ,c.description=#{description} where id = #{id}")
    int update(Course course);

    @Select("select * from t_course")
    @Results(id="courseMap",
        value = {
                @Result(column = "id", property = "id",jdbcType = JdbcType.INTEGER),
                @Result(column = "course_name", property = "courseName"),
                @Result(column = "minutes", property = "minutes"),
                @Result(column = "description", property = "description")
        })
    List<Course> findAll();

    @Select("select * from t_course where course_name like '%${courseName}%'")
    @ResultMap("courseMap")
    @MapKey("id")
    Map<Integer, Course> findMapByCourseName(@Param("courseName") String courseName);

    @Select("select * from t_course where id = #{value}")
    Course findById(Serializable id);
}
